<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------

namespace app\common\model\package;

use app\common\model\Base;

use think\db;

class PackageBuyLog extends Base
{
    protected $name = 'package_buy_log';

    //付款方式：0余额支付 1微信支付 2支付宝支付
    public $pay_types = [
        0 => '余额支付',
        1 => '微信支付',
        2 => '支付宝支付',
    ];
    //`state` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '支付状态：0未支付 1已支付',
    public $states = [
        0 => '未支付',
        1 => '已支付'
    ];

    public $types = [ //类型：0普通购买 1、注册赠送 2、购买赠送 3、实名赠送
        0 => '普通购买',
        1 => '注册赠送',
        2 => '购买赠送',
        3 => '实名赠送',
    ];

    /**
     * User:Simony
     * Function: 获取购买记录列表
     * @param $condition
     * @param int $page
     * @param string $field
     * @param string $order
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\exception\DbException
     * @throws db\exception\DataNotFoundException
     * @throws db\exception\ModelNotFoundException
     */
    public function getPackageBuyLogList($condition = [], $page = 0, $field = 'b_l.*,m.nickname', $order = 'b_l.id desc')
    {
        $res = $this->alias('b_l')
            ->join('member m', 'b_l.member_id=m.id', 'left')
            ->where($condition)
            ->field($field)
            ->order($order);

        if ($page) {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            $res = $res->toArray();
            return $res['data'];
        } else {
            return $res->select()->toArray();
        }
    }

}
